package com.zjm.jsp.servlet;

import com.zjm.jsp.pojo.Student;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ZJM
 * @date 2024/4/17 22:31
 */
@WebServlet("/search")
public class SearchServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Student> studentList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            studentList.add(new Student(i + 1, "name" + i, 18 + i, "phone" + i));
        }
        req.setAttribute("studentList", studentList);
        //获取请求调度器对象
        RequestDispatcher dispatcher = req.getRequestDispatcher("/pages/jsp10.jsp");
        //转发
        dispatcher.forward(req, resp);
    }
}
